package com.weidey.blogWeb.service.Impl;

import com.weidey.blog.domain.Article;
import com.weidey.blogWeb.domain.WebArticle;
import com.weidey.blogWeb.mapper.WebArticleMapper;
import com.weidey.blogWeb.mapper.WebUserMapper;
import com.weidey.blogWeb.service.IWebUserService;
import com.weidey.common.core.domain.AjaxResult;
import com.weidey.common.core.domain.entity.SysUser;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WebUserServiceImpl implements IWebUserService {

    @Resource
    private WebUserMapper webUserMapper;

    @Resource
    private WebArticleMapper webArticleMapper;

    @Override
    public SysUser getUserInfoById(long id) {
        return webUserMapper.selectUserInfoById(id);
    }

    @Override
    public AjaxResult getMyArticle(Long userId) {
        List<WebArticle> MyArticles = webArticleMapper.selectBlogArticleByAuthorId(userId);
        return AjaxResult.success(MyArticles);
    }

    @Override
    public AjaxResult getMyCollectArticle(Long userId) {
//        // 获取用户收藏数据
//        WebUser blogWebUser = webUserMapper.selectCollectRecord(userId);
//        //获得id字符串
//        String  StarListString = blogWebUser.getStarList();
//        //将字符串转换
//        ArrayStringConverter converter = new ArrayStringConverter(StarListString);
//        int[] StarArr =  converter.getArray();
//        if (StarArr.length>0){
//            // 根据收藏数据id查询对应的文章
//            List<Article> MyCollectArticles = webArticleMapper.selectArticleByStarArr(StarArr);
//            return AjaxResult.success(MyCollectArticles);
//        }
        return AjaxResult.success("您还没有收藏过文章");
    }

    @Override
    public AjaxResult getMyLikeArticle(Long userId) {
//        // 获取用户收藏数据
//        WebUser blogWebUser = webUserMapper.selectLikeRecord(userId);
//        //获得id字符串
//        String  StarLikeString =  blogWebUser.getLikeList();
//        //将字符串转换
//        ArrayStringConverter converter = new ArrayStringConverter(StarLikeString);
//        int[] StarArr =   converter.getArray();
//        if (StarArr.length>0){
//            // 根据点赞数据id查询对应的文章
//            List<Article> MyLikeArticles = webArticleMapper.selectArticleByLikeArr(StarArr);
//            return AjaxResult.success(MyLikeArticles);
//        }
        return AjaxResult.success("您还没有点赞过文章");

    }
}
